﻿using Microsoft.AspNetCore.Mvc;
using NaturalNote.Web.utils;

namespace NaturalNote.Web.Controllers
{
    public class FilesController : Controller
    {
        FileStorage fileStorage;

        public FilesController(FileStorage fileStorage)
        {
            this.fileStorage = fileStorage;
        }

        public IActionResult Index()
        {
            return View();
        }

        [HttpGet("myfile/{user}/{path}")]
        public IActionResult Path(string user, string path)
        {
            return View();
        }

        [HttpPost]
        public IActionResult CreatePath(string path, string name)
        {
            return View(path, name);
        }

        [HttpPost]
        [DisableRequestSizeLimit]
        public IActionResult Upload(string path)
        {
            var files = this.Request.Form.Files;
            foreach (var file in files)
            {
                var stream = file.OpenReadStream();
                var tempFileName = fileStorage.SaveTempFile(stream);
            }
            return Json("成功");
        }

        [HttpGet("downdload/{user}/{fileName}")]
        public IActionResult Download(string user, string fileName)
        {
            return File("","");
        }
        [HttpGet("images/{user}/{fileName}")]
        public IActionResult Images(string user, string fileName)
        {
            return File("","");
        }

    }
}
